﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import Engine.Events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.util.*;
    import com.greensock.*;
    import Engine.*;
    import fl.motion.easing.*;

    public class Dialog extends MovieClip {

        public static const TWEEN_TIME:Number = 0.25;
        public static const INTERNAL:Boolean = true;
        public static const EXTERNAL:Boolean = false;

        protected var m_content:DisplayObject = null;
        protected var m_modal:Boolean = true;
        protected var m_lightbox:Boolean = false;
        protected var m_shown:Boolean = false;
        protected var m_loaded:Boolean = false;
        protected var m_showOnLoad:Boolean = false;
        protected var m_jwindow:JWindow;
        protected var m_cursorId:int = 0;
        protected var m_centered:Boolean = true;
        private var m_zaspLoadHandle:int = 0;

        public function Dialog(_arg1:Boolean=true, _arg2:Boolean=false, _arg3:DisplayObject=null){
            if (_arg3 != null){
                this.m_content = _arg3;
            };
            this.m_loaded = _arg2;
            this.m_modal = _arg1;
        }
        public function isLockable():Boolean{
            return (false);
        }
        final protected function onDialogInitialized():void{
            if (this.m_content){
            };
            dispatchEvent(new LoaderEvent(LoaderEvent.LOADED));
            this.m_loaded = true;
            if (this.m_showOnLoad){
                this.m_showOnLoad = false;
                this.show();
            };
        }
        protected function useSystemCursor():Boolean{
            return (true);
        }
        public function show():void{
            if (!Global.ui){
                return;
            };
            Global.ui.turnOffHighlightedObject();
            if (this.m_loaded){
                this.visible = true;
                this.showTween();
                if (GlobalEngine.zaspManager){
                    GlobalEngine.zaspManager.zaspPopup();
                    if (this.m_zaspLoadHandle > 0){
                        GlobalEngine.zaspManager.zaspWaitEnd(this.m_zaspLoadHandle);
                        this.m_zaspLoadHandle = 0;
                    };
                };
                this.onShow();
            } else {
                if (((GlobalEngine.zaspManager) && (!(this.m_zaspLoadHandle)))){
                    this.m_zaspLoadHandle = GlobalEngine.zaspManager.zaspWaitStart("DIALOG", getQualifiedClassName(this));
                };
                this.m_showOnLoad = true;
            };
        }
        public function hide():void{
            this.hideTween(this.onHideComplete);
            this.onHide();
        }
        public function close():void{
            var dispObj:* = null;
            Global.ui.swapPopupAd("genericAd", false);
            dispObj = this;
            this.hideTween(function ():void{
                if (dispObj.parent){
                    dispObj.parent.removeChild(dispObj);
                };
                dispatchEvent(new Event(Event.CLOSE));
                onHideComplete();
            });
            this.onHide();
        }
        protected function onShow():void{
            if (this.m_shown == false){
                if (this.m_modal){
                    InputManager.disableInput();
                    Global.ui.mouseEnabled = false;
                    Global.ui.mouseChildren = false;
                };
                if (this.m_lightbox){
                    Global.ui.displayLightbox(true);
                };
                if (this.useSystemCursor()){
                    this.m_cursorId = UI.setCursor(null);
                };
                this.mouseEnabled = (this.mouseChildren = true);
                this.m_shown = true;
                Global.stage.addEventListener(FullScreenEvent.FULL_SCREEN, this.onFullScreen);
            } else {
                this.m_showOnLoad = true;
            };
            if (!Global.guide.isActive()){
                Sounds.play("dialogSpawn");
            };
        }
        protected function onHide():void{
            if (this.m_shown == true){
                if (this.m_modal){
                    InputManager.enableInput();
                    Global.ui.mouseEnabled = true;
                    Global.ui.mouseChildren = true;
                };
                if (this.m_lightbox){
                    Global.ui.displayLightbox(false);
                };
                this.m_shown = false;
                this.mouseEnabled = (this.mouseChildren = false);
                if (this.useSystemCursor()){
                    UI.removeCursor(this.m_cursorId);
                };
                Global.stage.removeEventListener(FullScreenEvent.FULL_SCREEN, this.onFullScreen);
            };
            this.m_showOnLoad = false;
        }
        protected function showTween():void{
            this.mouseEnabled = (this.mouseChildren = false);
            this.m_content.scaleX = (this.m_content.scaleY = 0);
            TweenLite.to(this.m_content, TWEEN_TIME, {
                scaleX:1,
                scaleY:1,
                ease:Back.easeOut,
                onUpdate:this.showTweenOnUpdate,
                onComplete:this.onShowComplete
            });
        }
        protected function hideTween(_arg1:Function):void{
            this.mouseEnabled = (this.mouseChildren = false);
            if (this.m_content){
                TweenLite.to(this.m_content, TWEEN_TIME, {
                    scaleX:0,
                    scaleY:0,
                    ease:Back.easeIn,
                    onUpdate:this.hideTweenOnUpdate,
                    onComplete:_arg1
                });
            } else {
                if (_arg1 == null){
                    _arg1();
                };
            };
            Sounds.play("dialogClose");
        }
        protected function showTweenOnUpdate():void{
            if (this.m_centered){
                this.centerPopup();
            };
        }
        protected function hideTweenOnUpdate():void{
            if (this.m_centered){
                this.centerPopup();
            };
        }
        protected function onHideComplete():void{
            this.visible = false;
        }
        public function onShowComplete():void{
            this.mouseEnabled = (this.mouseChildren = true);
        }
        protected function onFullScreen(_arg1:FullScreenEvent):void{
            this.centerPopup();
        }
        public function getDialogOffset():Point{
            return (new Point(0, 0));
        }
        public function centerPopup():void{
            var _local1:Point;
            var _local2:Number;
            var _local3:Number;
            if (this.m_jwindow){
                this.m_centered = true;
                _local1 = this.getDialogOffset();
                _local2 = (this.m_jwindow.getWidth() * this.m_content.scaleX);
                _local3 = (this.m_jwindow.getHeight() * this.m_content.scaleY);
                x = (((Global.stage.stageWidth - _local2) * 0.5) + _local1.x);
                y = (((Global.stage.stageHeight - _local3) * 0.5) + _local1.y);
            };
        }
        public function getVisibleBounds(_arg1:DisplayObject):Rectangle{
            var _local2:BitmapData = new BitmapData((Math.ceil(_arg1.width) + 1), (Math.ceil(_arg1.height) + 1), true, 0);
            _local2.draw(_arg1);
            var _local3:Rectangle = _local2.getColorBoundsRect(4294967295, 0, false);
            _local2.dispose();
            return (_local3);
        }
        public function setIsoPosition(_arg1:int, _arg2:int):Point{
            this.m_centered = false;
            var _local3:Point = IsoMath.tilePosToPixelPos(_arg1, _arg2);
            _local3 = IsoMath.viewportToStage(_local3);
            this.x = _local3.x;
            this.y = _local3.y;
            return (_local3);
        }
        public function setStagePosition(_arg1:int, _arg2:int):void{
            this.m_centered = false;
            this.x = _arg1;
            this.y = _arg2;
        }
        public function get isModal():Boolean{
            return (this.m_modal);
        }
        public function get isShown():Boolean{
            return (this.m_shown);
        }

    }
}//package Display 
